﻿using System;
using System.Collections.Generic;
using System.Text;

namespace P2P_Backup
{

    public class ItemArgs<T> : EventArgs
    {
        public ItemArgs(T item)
        {
            this.item = item;
        }
        private T item;
        public T Item
        {
            get { return item; }
        }
    }

    public class List<T> : System.Collections.Generic.List<T>
    {
        public List() { }
        public List(System.Collections.Generic.List<T> collection) : base(collection)
        {
            
        }
        
        public event EventHandler<ItemArgs<T>> ItemAdded;
        private void onAdded(T item)
        {
            EventHandler<ItemArgs<T>> handler = ItemAdded;
            if (handler != null) handler(this, new ItemArgs<T>(item));
        }
        public new void Add(T item)
        {
            base.Add(item);
            onAdded(item);
        }

        public event EventHandler Cleared;
        private void onCleared()
        {
            EventHandler handler = Cleared;
            if (handler != null) handler(this, new EventArgs());
        }
        public new void Clear()
        {
            base.Clear();
            onCleared();
        }
        


        public new void AddRange(IEnumerable<T> collection)
        {
            base.AddRange(collection);
            foreach (T item in collection)
            {
                onAdded(item);
            }
        }

        public event EventHandler<ItemArgs<T>> ItemRemoved;
        private void onRemoved(T item)
        {
            EventHandler<ItemArgs<T>> handler = ItemRemoved;
            if (handler != null) handler(this, new ItemArgs<T>(item));
        }
        public new void Remove(T item)
        {
            base.Remove(item);
            onRemoved(item);
        }
        
               
    }
}
